@extends('plugin.layout.base')
@section('add_css')

@endsection
@section('content')

    @php
        $banner=isset($banner)?json_decode($banner,1):[];

    @endphp
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-header">横幅设置</div>
            <div class="layui-card-body" pad15="">

                <div class="layui-form layui-form-kongqi" lay-filter="">

                    <input type="hidden" name="tpl" value="banner">
                    <table class="layui-table">
                        <tr style="display: none">
                            <td width="150">图片</td>
                            <td>标题</td>
                            <td>说明</td>
                            <td>优点</td>
                            <td>价格</td>
                            <td>优惠</td>
                            <td>操作</td>
                        </tr>
                        <tbody id="banner_body">
                        @if(!empty($banner))
                            @foreach($banner as $k=>$v)
                                <tr>
                                    <td>

                                        @include('plugin.'.$controller_base_lower.'.thumbPlace',[
                                           'data'=>[
                                               'name'=>'banner['.$k.'][img]',
                                               'value'=>$v['img']??'',
                                               'show'=>$v['img']??0,
                                               'title'=>'图片',
                                               'tips'=>'',
                                               'rq'=>1,
                                               'place'=>1,
                                               'obj'=>'banner'.$k.'Upload'
                                           ]])
                                    </td>
                                    <td>
                                        @include('admin.tpl.form.text',[
                                        'data'=>[
                                                 'name'=>'banner['.$k.'][title]',
                                                 'title'=>'标题',
                                                 'tips'=>'',
                                                 'value'=>$v['title']??'',
                                                 'rq'=>'rq'
                                               ]
                                         ])
                                        @include('admin.tpl.form.text',[
                                           'data'=>[
                                                    'name'=>'banner['.$k.'][sub_title]',
                                                    'title'=>'导航文字',
                                                    'tips'=>'',
                                                    'value'=>$v['sub_title']??'',
                                                    'rq'=>'rq'
                                                  ]
                                            ])
                                    </td>
                                    <td>
                                        @include('admin.tpl.form.textarea',[
                                           'data'=>[
                                                    'name'=>'banner['.$k.'][intro]',
                                                    'title'=>'介绍',
                                                    'tips'=>'',
                                                    'value'=>$v['intro']??'',
                                                    'rq'=>'rq'
                                                  ]
                                            ])
                                    </td>
                                    <td>
                                        @include('admin.tpl.form.textarea',[
                                           'data'=>[
                                                    'name'=>'banner['.$k.'][tedian]',
                                                    'title'=>'优点',
                                                    'tips'=>'1行一个，回车即可换行',
                                                    'value'=>$v['tedian']??'',
                                                    'rq'=>'rq'
                                                  ]
                                            ])
                                    </td>
                                    <td>
                                        @include('admin.tpl.form.text',[
                                         'data'=>[
                                                  'name'=>'banner['.$k.'][price]',
                                                  'title'=>'价格',
                                                  'tips'=>'',
                                                  'value'=>$v['price']??'',
                                                  'rq'=>'rq'
                                                ]
                                          ])

                                            @include('admin.tpl.form.text',[
                                             'data'=>[
                                                      'name'=>'banner['.$k.'][sale]',
                                                      'title'=>'优惠',
                                                      'tips'=>'',
                                                      'value'=>$v['sale']??'',
                                                      'rq'=>'rq'
                                                    ]
                                              ])

                                    </td>

                                    <td>
                                        @include('admin.tpl.form.text',[
                                          'data'=>[
                                                   'name'=>'banner['.$k.'][url]',
                                                   'title'=>'链接',
                                                   'tips'=>'',
                                                   'value'=>$v['url']??'',
                                                   'rq'=>'rq'
                                                 ]
                                           ])

                                            @include('admin.tpl.form.text',[
                                               'data'=>[
                                                        'name'=>'banner['.$k.'][text]',
                                                        'title'=>'链接文字',
                                                        'tips'=>'',
                                                        'value'=>$v['text']??'查看详情',
                                                        'rq'=>'rq'
                                                      ]
                                                ])

                                    </td>
                                    <td>
                                        <p>
                                            <a href="javascript:void(0)"
                                               class="layui-btn layui-btn-normal layui-btn-sm js-up">上移</a>
                                        </p>
                                        <p class="m-t-10">
                                            <a href="javascript:void(0)"
                                               class="layui-btn layui-btn-normal layui-btn-sm js-dowm">下移</a>
                                        </p>
                                        <p class="m-t-10">
                                            <a href="javascript:void(0)"
                                               class="layui-btn layui-btn-danger layui-btn-sm js-del">删除</a>
                                        </p>
                                    </td>
                                </tr>

                            @endforeach
                        @endif

                        </tbody>
                    </table>
                    <button class="layui-btn layui-btn-dark js-add-banner">增加横幅</button>


                    <div class="layui-form-item" style="margin-top: 50px">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="config">确认保存</button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>


@endsection
@section('foot_js')
    <script>
        layui.use(['index', 'form'], function () {
            var $ = layui.$
                , jquery = $
                , form = layui.form;
            var up_key = '{{ count($banner)??0 }}';
            $(".js-add-banner").click(function () {


                var html = '<tr> <td> <div class="layui-input-block "> ' +
                    '<div class="layui-uploads-pic layui-row layui-col-space10" id="aff5230f7f29fe9d210eddd08aba924b' + up_key + '"> ' +
                    '<button class="layui-btn layui-btn-xs layui-btn-info" kq-event="upload_place" data-type="image" data-more="0" ' +
                    'data-obj="#aff5230f7f29fe9d210eddd08aba924b' + up_key + '">文件库选择</button> ' +
                    '<div class="item layui-col-xs12 upload-item upload-item-one "> ' +
                    '<input type="hidden" name="banner[' + up_key + '][img]" value="" class="upload-item-field" placeholder="图片" lay-verify="thumb">' +
                    ' <img src="" style="max-width: 150px" class="upload-item-pic" alt="">' +
                    ' <div class="item-tools"> <button type="button" data-src="" kq-event="show_pic" ' +
                    'class="layui-btn layui-btn-radius layui-btn-sm layui-btn-primary">' +
                    '<i class="ti-eye"></i> 查看 </button> <button type="button" ' +
                    'kq-event="del_upload_pic" class="layui-btn layui-btn-radius layui-btn-sm layui-btn-danger">' +
                    '<i class="mdi mdi-delete"></i> 删除 </button> </div>' +
                    ' </div> <div class="item layui-col-xs12 "> ' +
                    '<a href="javascript:void(0)" class="pic-add" ' +
                    'id="banner1Upload" data-open_file="0" kq-event="upload_place" data-type="image" data-more="0" ' +
                    'data-obj="#aff5230f7f29fe9d210eddd08aba924b' + up_key + '"></a> </div> ' +
                    '</div> </div> </td> <td> <div class="layui-form-item"> ' +
                    '<label class="layui-form-label"> <strong class="item-required">*</strong> 标题 </label>    ' +
                    '<div class="layui-input-block"> <input type="text" name="banner[' + up_key + '][title]" ' +
                    'value="" placeholder="" lay-verify="rq" id="banner[' + up_key + '][title]" ' +
                    'autocomplete="off" class="layui-input"> </div> </div> <div class="layui-form-item"> ' +
                    '<label class="layui-form-label"> <strong class="item-required">*</strong> 导航文字 ' +
                    '</label>    <div class="layui-input-block"> ' +
                    '<input type="text" name="banner['+up_key+'][sub_title]" value="" placeholder="" lay-verify="rq"' +
                    ' id="banner['+up_key+'][sub_title]" autocomplete="off" class="layui-input">' +
                    ' </div> </div></td> <td> ' +
                    '<div class="layui-form-item"> <label class="layui-form-label">' +
                    ' <strong class="item-required">*</strong> 介绍 </label>  ' +
                    '  <div class="layui-input-block">' +
                    ' <textarea name="banner[' + up_key + '][intro]" placeholder="" lay-verify="rq" autocomplete="off" ' +
                    'id="banner[' + up_key + '][intro]" class="layui-textarea"></textarea>' +
                    ' </div> </div> </td> <td> <div class="layui-form-item"> ' +
                    '<label class="layui-form-label"> <strong class="item-required">*</strong> 优点' +
                    ' </label>    <div class="layui-input-block">' +
                    ' <textarea name="banner[' + up_key + '][tedian]" placeholder="1行一个，回车即可换行" lay-verify="rq" ' +
                    'autocomplete="off" id="banner[' + up_key + '][tedian]" class="layui-textarea"></textarea>' +
                    ' </div> </div></td> <td> <div class="layui-form-item"> ' +
                    '<label class="layui-form-label"> <strong class="item-required">*</strong> 价格 </label>   ' +
                    ' <div class="layui-input-block"> ' +
                    '<input type="text" name="banner[' + up_key + '][price]" value="" placeholder="" lay-verify="rq" id="banner[' + up_key + '][price]"' +
                    ' autocomplete="off" class="layui-input"> </div> </div> ' +
                    ' <div class="layui-form-item"> ' +
                    '<label class="layui-form-label"> <strong class="item-required">*</strong> 优惠 </label>  ' +
                    '  <div class="layui-input-block"> <input type="text" name="banner[' + up_key + '][sale]" value="" placeholder="" ' +
                    'lay-verify="rq" id="banner[' + up_key + '][sale]" autocomplete="off" class="layui-input"> </div> ' +
                    '</div> </td><td><div class="layui-form-item"> ' +
                    '<label class="layui-form-label"> <strong class="item-required">*</strong> 链接 </label> ' +
                    '<div class="layui-input-block"> <input type="text" name="banner['+up_key+'][url]" value="" placeholder="链接"' +
                    ' lay-verify="rq" id="banner['+up_key+'][url]" autocomplete="off" class="layui-input">' +
                    ' </div> </div><div class="layui-form-item"> <label class="layui-form-label"> ' +
                    '<strong class="item-required">*</strong> 链接文字 </label> ' +
                    '<div class="layui-input-block"> <input type="text" name="banner['+up_key+'][text]" ' +
                    'value="" placeholder="链接文字" lay-verify="rq" id="banner['+up_key+'][text]" ' +
                    'autocomplete="off" class="layui-input"> </div> </div></td> <td>' +
                    ' <p> <a href="javascript:void(0)" class="layui-btn layui-btn-normal layui-btn-sm js-up">上移</a> ' +
                    '</p> <p class="m-t-10"> <a href="javascript:void(0)" class="layui-btn layui-btn-normal layui-btn-sm js-dowm">下移</a>' +
                    ' </p> ' +
                    ' <p class="m-t-10"> <a href="javascript:void(0)"class="layui-btn layui-btn-danger layui-btn-sm js-del">删除</a> </p>' +
                    '</td> </tr>';
                up_key++;
                $("#banner_body").append(html);
            })
            $(document).on('click', '.js-up', function () {
                var onthis = $(this).parents("tr");
                var getup = $(this).parents("tr").prev("tr");
                if (getup.html() != null) {
                    $(getup).before(onthis);
                }

            })
            //下移动
            $(document).on('click', '.js-dowm', function (event) {

                var onthis = $(this).parents("tr");
                var getup = $(this).parents("tr").next("tr");
                if (getup.html() != null) {
                    $(getup).after(onthis);
                }


            });
            $(document).on('click', '.js-del', function (event) {

                var onthis = $(this).parents("tr");
                onthis.remove();


            });
            form.on('submit(config)', function (obj) {
                //提交修改
                $.ajax({
                    url: '{{ action($controller.'@store') }}'
                    , method: 'post'
                    , data: obj.field
                    , success: function (res) {
                        layer.msg(res.msg);
                    }
                });

                return false;
            });


        });
    </script>

@endsection